<?php
include("../config.php");
$encode = base64_encode($_SERVER["REMOTE_ADDR"]);
$json = json_decode(file_get_contents("./Cache/admin.txt"),true);
$Cache_pwd=$json[$encode]?$json[$encode]:"0";
if($Cache_pwd<time())
{
exit("<script language='javascript'>alert('请先登陆！');window.location.href='./login.php';</script>");
}
elseif(isset($_POST['new_pass'])!=null&&isset($_POST['old_pass'])!=null)
{
$old_password=$_POST["old_pass"];
$password=$config["admin"]["admin_pass"];
$new_password=$_POST["new_pass"];
if($old_password == $password)
{
$data=file_get_contents("../config.php");
$data=str_replace($password,$new_password,$data);
file_put_contents("../config.php",$data);
exit("<script language='javascript'>alert('修改成功！');history.go(-1);</script>");
}else{
exit("<script language='javascript'>alert('旧密码不正确！');history.go(-1);</script>");
}
}
?>

<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<meta name="keywords" content="<?php echo $web["code"]; ?>">
<meta name="description" content="<?php echo $web["jianjie"]; ?>">
<meta name="author" content="yinq">
<title><?php echo $web["ming"]; ?>API - 修改密码</title>
<link rel="icon" href="http://q2.qlogo.cn/headimg_dl?dst_uin=<?php echo $web["qq"]; ?>&spec=5" type="image/ico">
<meta name="keywords" content="<?php echo $web["keywords"]; ?>">
<meta name="description" content="<?php echo $web["description"]; ?>">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<link rel="stylesheet" type="text/css" href="css/materialdesignicons.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/animate.min.css">
<link rel="stylesheet" type="text/css" href="css/style.min.css">
</head>

<body>
<!--页面loading end-->
<div class="lyear-layout-web">
  <div class="lyear-layout-container">

<?php require_once("./head.php")?>

    <!--页面主要内容-->
    <main class="lyear-layout-content">
      
      <div class="container-fluid p-t-15">
        
        <div class="row">
          
          <div class="col-lg-12">
            <div class="card">
              <div class="tab-content">
                <div class="tab-pane active">
                  
                <form method="POST" action="#!" class="site-form">
                  <div class="form-group">
                    <label for="old-password">旧密码</label>
                    <input type="password" class="form-control" name="old_pass" id="old-password" placeholder="输入账号的原登录密码">
                  </div>
                  <div class="form-group">
                    <label for="new-password">新密码</label>
                    <input type="password" class="form-control" name="new_pass" id="new-password" placeholder="输入新的密码">
                  </div>
                  <button type="submit" class="btn btn-primary">修改密码</button>                  
                    </div>
                  </form>
                  
                </div>
              </div>
      
            </div>
          </div>
              
        </div>
        
      </div>
    
    </main>
    <!--End 页面主要内容-->
  </div>
</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="js/main.min.js"></script>
</body>
</html>